package dd.prog2.musterExercises.ws12set04_vector;

import static dd.prog2.musterExercises.ws12set04_vector.VectorMathFactory.*;


public class VectorMathTest {

	public static void testOperations() {
		try {
			Vector v1 = createVector(10, 20);
			// Vector v1 = createVector(10, 20, 3);
			Vector v2 = createVector(-10, -20);
			Matrix m = createMatrix(2, 2);
			Matrix rm = createRotationMatrix(180);
			m.set(0, 1, 1);
			m.set(1, 0, 1);
			System.out.println("v1+v2 = " + v1.plus(v2));
			System.out.println("m*v1 = " + m.multiply(v1));
			System.out.println("rm*v1 = " + rm.multiply(v1));
			System.out.println("v1 = " + v1);
			System.out.println("v2 = " + v2);
			System.out.println("m = " + m);
		} catch (Exception e) {
			System.out.println("In " + e.getStackTrace()[0] + ":\n"
					+ e.getClass().getName() + ": " + e.getMessage());
		}
	}

	public static void startPerformanceTest() {
		try {
			long t1 = System.nanoTime();
			for (int i = 0; i < 1000000; i++) {
				Vector v1 = createVector(10, 20);
				// Vector v1 = createVector(10, 20, 30);
				Vector v2 = createVector(20, 20);
				Matrix rm = createRotationMatrix(90);
				rm.multiply(v1.plus(v2));
			}
			long t2 = System.nanoTime();
			System.out.println("Time: " + ((t2 - t1) / 1000000) + " sec");
		} catch (Exception e) {
			System.out.println("In " + e.getStackTrace()[0] + ":\n"
					+ e.getClass().getName() + ": " + e.getMessage());
		}
	}

	public static void main(String[] args) {
		VectorMathFactory.enableEfficientMode(false);
		System.out.println("Default implementation:");
		testOperations();
		startPerformanceTest();
		VectorMathFactory.enableEfficientMode(true);
		System.out.println("Efficient implementation:");
		testOperations();
		startPerformanceTest();
	}
}
